package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 其他参数
 * @author stone
 * @date 2022/09/02 14:18
 */
@RestController
public class OtherParameterController {

    @RequestMapping("reqresp")
    public BaseRespVo reqresp(HttpServletRequest request, HttpServletResponse response) {
        return BaseRespVo.ok();
    }

    @RequestMapping("cookies")
    public BaseRespVo cookies(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if ("songge".equals(cookie.getName())) {
                System.out.println("找到你了！");
            }
            System.out.println(cookie.getName() + "  -- > " + cookie.getValue());
        }
        return BaseRespVo.ok();
    }

    @RequestMapping("session1")
    public BaseRespVo session1(HttpSession session, String username) {
        session.setAttribute("username", username);
        return BaseRespVo.ok();
    }
    @RequestMapping("session2")
    public BaseRespVo session2(HttpServletRequest request) {
        HttpSession session = request.getSession();
        Object username = session.getAttribute("username");
        System.out.println("username = " + username);
        return BaseRespVo.ok();
    }
}
